package com.hongkzh.www.look.media.presenter;

import com.hongkzh.www.look.media.model.bean.CarouselBean;
import com.hongkzh.www.look.media.model.bean.Top10Bean;
import com.hongkzh.www.look.media.model.bean.UserCategoryBean;
import com.hongkzh.www.look.media.view.iview.MediaIView;
import com.hongkzh.www.other.okhttp.CallBackUtil;
import com.hongkzh.www.other.okhttp.OkhttpUtil;
import com.hongkzh.www.presenter.BasePresenter;

import okhttp3.Call;

import static com.hongkzh.www.other.api.Api.GETCAROUSELLISTMEDIAADV;
import static com.hongkzh.www.other.api.Api.GETTOP10LIST;
import static com.hongkzh.www.other.api.Api.USERCATEGORYLIST;

/**
 * 自媒体
 */
public class MediaPresenter extends BasePresenter<MediaIView> {
//    private int pageNumber = 1;
//    private boolean lastPage = false;

    public MediaPresenter getCarouselList() {
        OkhttpUtil.okHttpPost(GETCAROUSELLISTMEDIAADV, new CallBackUtil<CarouselBean>() {
            @Override
            public void onFailure(Call call, Exception e) {
                getIView().onError(e);
            }

            @Override
            public void onResponse(CarouselBean response) {
                getIView().setCarouselList(response);
            }
        });
        return this;
    }

    public MediaPresenter getUserCategoryList(String loginId) {
        OkhttpUtil.okHttpPost(USERCATEGORYLIST(loginId), new CallBackUtil<UserCategoryBean>() {
            @Override
            public void onFailure(Call call, Exception e) {
                getIView().onError(e);
            }

            @Override
            public void onResponse(UserCategoryBean response) {
                getIView().setUserCategoryList(response);
            }
        });
        return this;
    }

    public MediaPresenter getTop10List() {
        OkhttpUtil.okHttpPost(GETTOP10LIST, null, new CallBackUtil<Top10Bean>() {
            @Override
            public void onFailure(Call call, Exception e) {
                getIView().onError(e);
            }

            @Override
            public void onResponse(Top10Bean response) {
                getIView().setTop10List(response);
            }
        });
        return this;
    }

//    public MediaPresenter getAllProductByUserId(String uid) {
//        OkhttpUtil.okHttpPost(GETALLProductBYUSERID(uid, String.valueOf(pageNumber), null, null), new CallBackUtil<MediaProductBean>() {
//            @Override
//            public void onFailure(Call call, Exception e) {
//                getIView().onError(e);
//            }
//
//            @Override
//            public void onResponse(MediaProductBean response) {
//                lastPage = response.getData().isLastPage();
//                if (lastPage) getIView().onLastPage(lastPage);
//                getIView().setAllProductByUserId(response);
//            }
//        });
//        return this;
//    }
//
//    public void loadmore(String uid) {
//        if (!lastPage) {
//            pageNumber += 1;
//            getAllProductByUserId(uid);
//        }
//    }
}
